package com.gamex.findit.controller.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.gamex.findit.Constants;
import com.gamex.findit.internal.DefaultConfig;
import com.gamex.findit.model.ItemPurchaseHist;
import com.gamex.findit.model.MemberItem;
import com.gamex.findit.model.MemberSkill;
import com.gamex.findit.model.Skill;
import com.gamex.findit.service.CommonCodeService;
import com.gamex.findit.service.ItemPurchaseHistService;
import com.gamex.findit.service.MemberSkillService;
import com.gamex.findit.service.SkillService;
import com.gamex.findit.util.CommonUtil;
import com.gamex.findit.util.Generator;

@Controller("adminItemPurchaseHist")
public class ItemPurchaseHistController {
	
	private static final Logger logger = LoggerFactory.getLogger(ItemPurchaseHistController.class);
	
	@Autowired ItemPurchaseHistService itemPurchaseHistService;
	@Autowired DefaultConfig config;
	
	/**
	 * @param session
	 * @param request
	 * @param response
	 * @param model
	 * @param itemPurchaseHist
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/itemPurchaseHistList")
	public String itemPurchaseHistList( HttpSession session
								, HttpServletRequest request
								, HttpServletResponse response
								, Model model
								, @ModelAttribute ItemPurchaseHist itemPurchaseHist) throws Exception{

		int count = itemPurchaseHistService.getItemPurchaseHistCount(itemPurchaseHist);
		List<ItemPurchaseHist> result = itemPurchaseHistService.getItemPurchaseHist(itemPurchaseHist);
		model.addAttribute("list", result);
		model.addAttribute("count", count);
		model.addAttribute("pageNo", itemPurchaseHist.getPageNo());
		model.addAttribute("pageGroup", itemPurchaseHist.getPageGroup());
		model.addAttribute("searchParam", itemPurchaseHist);
	return "/purchaseHist/itemPurchaseHistList";
	}
	
	/**
	 * @param session
	 * @param request
	 * @param response
	 * @param model
	 * @param itemPurchaseHist
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/addItemPurchaseHist")
	public String addItemPurchaseHist( HttpSession session
							   , HttpServletRequest request
							   , HttpServletResponse response
							   , Model model
							   , @ModelAttribute ItemPurchaseHist itemPurchaseHist) throws Exception{
		
		itemPurchaseHistService.insertItemPurchaseHist(itemPurchaseHist);
		model.addAttribute("searchParam", itemPurchaseHist);
	return "redirect:/admin/itemPurchaseHistList";
	}
	
	/**
	 * @param session
	 * @param request
	 * @param response
	 * @param model
	 * @param itemPurchaseHist
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/itemPurchaseHistView")
	public String viewtemPurchaseHist( HttpSession session
									, HttpServletRequest request
									, HttpServletResponse response
									, ModelMap model
									, @ModelAttribute ItemPurchaseHist itemPurchaseHist) throws Exception{
		
		model.addAttribute("view", itemPurchaseHistService.getItemPurchaseHistView(itemPurchaseHist.getSeq()));
		model.addAttribute("searchParam", itemPurchaseHist);
	return "/purchaseHist/itemPurchaseHistView";
	}
	
	/**
	 * @param session
	 * @param request
	 * @param response
	 * @param model
	 * @param file
	 * @param itemPurchaseHist
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/updateItemPurchaseHist.*")
	public String updateItemPurchaseHist( HttpSession session
							  , HttpServletRequest request
							  , HttpServletResponse response
							  , Model model
							  , @RequestParam("file") MultipartFile file
							  , @ModelAttribute ItemPurchaseHist itemPurchaseHist) throws Exception{
		
		itemPurchaseHistService.updateItemPurchaseHist(itemPurchaseHist);
		
	return "redirect:/admin/itemPurchaseHistList";
	}
	
	/**
	 * @param session
	 * @param request
	 * @param response
	 * @param model
	 * @param itemPurchaseHist
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/admin/deleteItemPurchaseHist")
	public String deleteItemPurchaseHist( HttpSession session
							  , HttpServletRequest request
							  , HttpServletResponse response
							  , Model model
							  , @ModelAttribute ItemPurchaseHist itemPurchaseHist) throws Exception{
		
		itemPurchaseHistService.deleteItemPurchaseHist(itemPurchaseHist.getSeq());
		
	return "redirect:/admin/itemPurchaseHistList";
	}
	
}
